<template>
  <div id="app">
    <HelloWorld v-if="currentPage === 'home'" @navigate="changePage" />
    <SendCorrectionImage v-if="currentPage === 'correction'" @navigate="changePage" />
  </div>
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'
import SendCorrectionImage from './pages/sendCorrectionImage.vue'

export default {
  name: 'app',
  components: {
    HelloWorld,
    SendCorrectionImage
  },
  data() {
    return {
      currentPage: 'home'
    }
  },
  mounted() {
    // 监听URL hash变化
    window.addEventListener('hashchange', this.handleHashChange);
    this.handleHashChange();
  },
  beforeDestroy() {
    window.removeEventListener('hashchange', this.handleHashChange);
  },
  methods: {
    changePage(pageName) {
      this.currentPage = pageName;
      // 更新URL hash
      window.location.hash = pageName === 'home' ? '' : pageName;
    },
    handleHashChange() {
      // 从URL hash获取页面名称
      const hash = window.location.hash.slice(1);
      if (hash === 'pages/sendCorrectionImage' || hash === 'correction') {
        this.currentPage = 'correction';
      } else {
        this.currentPage = 'home';
      }
    }
  }
}
</script>

<style>
body {
    display: block;
    margin: 0 !important;
    overflow-x: auto;
}
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}
</style>